package rgbos.forum.domain;

import java.util.Date;
import java.util.Vector;

public class Topic extends ForumElement implements Comparable<Topic> {
	private int viewCount_;
	private Vector<Integer> posts_;
	/**
	 * @param id_
	 * @param title_
	 * @param authorName_
	 * @param creationDate_
	 * @param postCount_
	 * @param viewCount_
	 */
	public Topic(int id_, String title_, String authorName_, Date creationDate_,Vector<Integer> post_,
			int postCount_, int viewCount_) {
		super(id_, title_, authorName_, creationDate_);
		this.viewCount_ = viewCount_;
		posts_ = post_;			
	}

	/**
	 * @return the postCount_
	 */
	public int getPostCount() {
		if (posts_!=null)
			return posts_.size();
		return 0;		
	}

	/**
	 * @return the viewCount_
	 */
	public int getViewCount() {
		return viewCount_;
	}
	public Vector<Integer> getPostVector() {
		return posts_;
	}
	public boolean addNewPost(Integer postID) {
		posts_.add(postID);
		return true;
	}
	public boolean deletePost(Integer postID) {
		posts_.remove(postID);
		return true;
	}
	public void setPostVec(Vector<Integer> posts){
		posts_ = posts;
	}
	public String getTopicAsString(){
		return super.getElementAsString()+this.getPostCount()+DELIMITER+this.viewCount_;
	}

	@Override
	public int compareTo(Topic o) {
		if (this.getId_() < o.getId_())
			return 1;
		else if (this.getId_() > o.getId_())
			return -1;
		else
			return 0;
	}
}
